from flask import Flask, render_template
from datetime import datetime

app = Flask(__name__)


class User:

    def __init__(self, name, age):
        self.name = name
        self.age = age


def date_format(value, format="%Y年%m月%d日 %H:%M"):
    return value.strftime(format)


app.add_template_filter(date_format)


@app.route('/')
def hello_world():
    user = User(name="王者荣耀", age=12)
    time = datetime.now()
    return render_template("index.html", user=user, time=time)


@app.route("/control")
def control_statement():
    age = 36
    books = [{"name": "三国演义", "author": "罗贯中"}, {"name": "红楼梦", "author": "曹雪芹"}]
    return render_template("control.html", age=age, books=books)


if __name__ == '__main__':
    app.run()
